<?php

/**
 * Created by phpstorem.
 * User: yangakw@qq.com
 * Sign: 猥琐发育，别浪
 * Date: 2018-06-23
 * Time: 上午 9:59
 */
class Ad extends CI_Model
{
    public function by_id($id)
    {
        $data = $this->db->where("id",$id)->from('ad')->get()->row();
        return $data;
    }
    public function del_by_id($id)
    {
        $data = $this->db->where("id",$id)->from('ad')->delete();
        return $data;
    }
    public function by_user_id($user_id)
    {
        $data = $this->db->where("user_id",$user_id)->from('ad')->get()->result();
        return $data;
    }
    public function save($data){
        if( isset($data["id"]) && empty($data["id"]) ){
            unset($data["id"]);
            $this->db->insert("ad",$data);
        }else if(isset($data["id"]) && !empty($data["id"])){
            if(isset($data['id'])){
                $this->db->where('id', $data['id']);
                $this->db->update('ad', $data);
            }
        }
        return true;
    }
}